package com.sh_rw.label.common.parser;

import com.sh_rw.label.bean.BasicParam;
import com.sh_rw.label.listener.ParserListener;
import com.sh_rw.label.utils.HexUtils;

/**
 * Created by rw-duke on 2018/4/8.
 */

public class _BaseArgParser extends Parser {
    private BasicParam basicParam;

    @Override
    public void onLabelParser(byte[] data, ParserListener listener) {
//        super.onLabelParser(data, listener);
//        if (isIntercept) {
        basicParam = new BasicParam();

        basicParam.head = HexUtils.toHexString(data[0], data[1], data[2], data[3]);
        basicParam.length = HexUtils.toHexString(data[4], data[5]);
        basicParam.devId = HexUtils.toHexString(data[6], data[7], data[8], data[9]);
        basicParam.cmd = HexUtils.toHexString(data[10]);
        basicParam.sn = HexUtils.toHexString(data[11]);
        basicParam.encryption = HexUtils.toHexString(data[12]);
        basicParam.setDataInterval(HexUtils.toHexString(data[13]));
        basicParam.setHeartbeatInterval(HexUtils.toHexString(data[14]));
        basicParam.setGpsInterval(HexUtils.toHexString(data[15]));
        basicParam.setFilterPattern(HexUtils.toHexString(data[16]));
        basicParam.setFilterTime(HexUtils.toHexString(data[17]));
        basicParam.setBuzzer(HexUtils.toHexString(data[18]));
        basicParam.setBaudRate(HexUtils.toHexString(data[19]));
        basicParam.setReply(HexUtils.toHexString(data[20]));

        basicParam.setRev1(HexUtils.toHexString(data[21]));
        basicParam.setRev2(HexUtils.toHexString(data[22]));
        basicParam.setRev3(HexUtils.toHexString(data[23]));
        basicParam.setRev4(HexUtils.toHexString(data[24]));
        basicParam.setRev5(HexUtils.toHexString(data[25]));
        basicParam.setRev6(HexUtils.toHexString(data[26]));
        basicParam.setRev7(HexUtils.toHexString(data[27]));
        basicParam.setRev8(HexUtils.toHexString(data[28]));
        basicParam.checkSum = HexUtils.toHexString(data[29]);

        listener.onBaseArgCallback(basicParam);
//        }
    }

    @Override
    public boolean check(byte[] data) {
        return true;
    }
}
